package competition.cig.cs478;

import ch.idsia.ai.agents.Agent;
import ch.idsia.mario.environments.Environment;

import competition.cig.cs478.backprop.Network;
import competition.cig.cs478.backprop.NetworkAdapter;
import competition.cig.robinbaumgarten.AStarAgent;

public class CS478_AStar_Backprop_Learner implements Agent {

	private Network network;
	private NetworkAdapter networkAdapter;
	private Agent aStarAgent;
	private double learningRate;
	private double momentum;
	
	public CS478_AStar_Backprop_Learner(Network network) {
		this.network = network;
		this.networkAdapter = new NetworkAdapter();
		this.aStarAgent = new AStarAgent();
		this.learningRate = 0.01;
		this.momentum = 0.0;
	}
	
	public void setNetwork(Network network) {
		this.network = network;
	}
	
	@Override
	public boolean[] getAction(Environment observation) {
		network.update(networkAdapter.getInput(observation));
		boolean[] action = aStarAgent.getAction(observation);
		network.backPropagate(networkAdapter.getTargets(action), learningRate, momentum);
		return action;
	}

	@Override
	public String getName() {
		return "CS478_AStar_Backprop_Learner : LR=" + learningRate + " M=" + momentum + " " + aStarAgent.getName();
	}

	@Override
	public AGENT_TYPE getType() {
		return aStarAgent.getType();
	}

	@Override
	public void reset() {
		aStarAgent.reset();
	}

	@Override
	public void setName(String name) {
		aStarAgent.setName(name);
	}

}
